<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <script>
        let booleanColor = prompt('请你传递true/false，我会给出随机颜色')
        let color = null
        if (booleanColor === 'true' || booleanColor === null) {
            color = getSixteenColor();
        }
        else {
            color = getRgbColor();
        }
        
        document.write(`<div style="width: 100px;height: 100px;margin: auto; background-color: ${color};">
    </div>`)
        // 获取n-m之间的随机数
        function getRandomColor(n, m) {
            return Math.floor(Math.random() * (m - n + 1)) + n
        }

        function getRgbColor() {
            let rgbColor = 'rgb'
            for (let index = 1; index <= 3; index++) {
                if (index === 1) {
                    rgbColor += '(' + getRandomColor(0, 255) + ","
                }
                else if (index == 3) {
                    rgbColor += getRandomColor(0, 255) + ")"
                }
                else {
                    rgbColor += getRandomColor(0, 255) + ","
                }
            }
            return rgbColor
        }
        function getRandomHexChar() {
            const chars = "0123456789abcdef";
            return chars[Math.floor(Math.random() * chars.length)];
        }

        function getSixteenColor() {
            let color = '#'
            for (let index = 1; index <= 6; index++) {
                color += getRandomHexChar()
            }
            return color
        }
    </script>
</body>

</html>